<include file="Public/head"/>
<body class="no-skin">
<include file="Public/header"/>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>
    <include file="Public/sidebar"/>
        <div class="main-content">
            <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
                <include file="Public/breadcrumbs"/>
                <!-- /section:basics/content.breadcrumbs -->
                    <div class="page-content">
                        <include file="Public/set"/>

                        <!-- /section:settings.box -->
                        <div class="row">
                            
                            <div class="col-xs-12 "  style="padding: 35px;" >
                                <div class="row">
                                    <h3>添加采购表头</h3>
                                    <form action="" method="post">
                                        <div class="input-group">
                                            <div class="input-group-addon">
                                                需求日期
                                            </div>
                                            <input type="date" name="need_date" class="form-control" value="{$head['need_date']|date="Y/m/d",###}">
                                        </div>
                                        <div class="input-group">
                                            <div class="input-group-addon">
                                                供应商编号
                                            </div>
                                            <input type="text" name="vendor_code" class="form-control ckg" placeholder="供应商编号" value="{$head['vendor_code']}">
                                        </div>
                                        <div class="input-group">
                                            <div class="input-group-addon">
                                                笔记
                                            </div>
                                            <input type="text" name="note" class="form-control" class="form-control" value="{$head['note']}">
                                        </div>
                                        <!-- <div class="row">
                                            <span class="coc btn btn-primary">添加采购内容</span>
                                        </div> -->

                                        <div class="row line_h" >
                                            <h3>采购内容</h3>            
                                            <table class="table line_table">
                                                <tr>
                                                    <th>行号</th>
                                                    <th>料号</th>
                                                    <th>单位</th>
                                                    <th>数量</th>
                                                    <th>单价</th>
                                                    <th>记录</th>
                                                    <th>操作</th>
                                                   <!--  <th>金额</th> -->
                                                    
                                                </tr>

                                                <volist name="main" id="vo">
                                                    <tr class="lh{$i}">
                                                        <td><input type="text" name="number[]" placeholder="行号" value="{$i}"></td>
                                                        <td><input type="text" name="stockid[]" placeholder="料号" class="stockid{$i}" onclick='show_item({$i})' value="{$vo['stockid']}"></td>
                                                        <td><input type="text" name="uom[]" placeholder="单位" onclick='show_item({$i})' class="uom{$i}" value="{$vo['uom']}"></td>
                                                        <td><input type="number" name="quantity[]" placeholder="数量"  value="{$vo['quantity']}"></td>
                                                        <td><input type="text" name="price[]" onclick='show_item({$i})' placeholder="单价" class="price{$i}" value="{$vo['price']}"></td>
                                                        <td><input type="text" name="notee[]" placeholder="记录" value="{$vo['note']}"></td>
                                                        <td><span onclick="dellh({$i})">删除</span></td>
                                                        <!-- <td><input type="text" name="liaohao" placeholder="金额"></td> -->
                                                    </tr>
                                                </volist>
                                            </table>
                                            <span class="btn btn-primary btn-sm" onclick='addrtr()'>添加行数</span>
                                            <div class="row">
                                                <button class="btn btn-success">更新采购单</button>
                                            </div>            
                                        </div>                        
                                    </form>
                                </div>
                            </div><!-- /.col -->
                        </div><!-- /.row -->
                    </div><!-- /.page-content -->
                </div>
            </div><!-- /.main-content -->
        <include file="Public/footer"/>

        </div><!-- /.main-container -->

        <include file="Public/footerjs"/>
    <!-- inline scripts related to this page -->

<div class="modal fade ck-item" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
        <div class="modal-header">
          <h3 class="modal-title">
            料号查询
          </h3>
        </div>
        <div class="modal-body">
            <div class="row">
                <div class="col-xs-3 ">
                    <input type="text" name="vendor-name" class="form-control item-no" placeholder="料号">
                </div>
                <div class="col-xs-3 ">
                    <input type="text" name="vendor-name" class="form-control iten-de" placeholder="物料描述">
                </div>
                <div class="col-xs-3">
                    <input type="text" name="vendor-code" class="form-control item-ve" placeholder="供应商编号">
                </div>
                <div class="col-xs-1">
                    <button class="btn btn-primary btn-sm item-search">
                        <span class="glyphicon glyphicon-search"></span> 搜索
                    </button>
                </div>
            </div>
            <div class="row">
                <table class="item-table table">
                    
                </table>
                
            </div> 
            <div class="row text-center">
                <button class="btn btn-defalut" onclick="item_desc()"><<</button>
                <button class="btn btn-defalut" onclick="item_add()">>></button>
            </div>         
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        </div>

    </div>
  </div>
</div>



<div class="modal fade ck-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
          <h3 class="modal-title">
              企业编号查询
          </h3>
      </div>
      <div class="modal-body">
        <div class="col-xs-3 col-xs-offset-4">
            <input type="text" name="vendor-name" class="form-control vendor-input-code" placeholder="供应商编号">
        </div>
        <div class="col-xs-3">
            <input type="text" name="vendor-code" class="form-control vendor-input-name" placeholder="供应商名称">
        </div>
        <div class="col-xs-1">
            <button class="btn btn-primary btn-sm vendor-search">
                <span class="glyphicon glyphicon-search"></span> 搜索
            </button>
        </div>
        <div class="row" >
            <table class="table table-bordered  vendor-table">
                <tr >
                    <th class="text-center">供应商编号</th>
                    <th class="text-center">供应商名称</th>
                    <th class="text-center">联系人</th>
                    <th class="text-center">联系电话</th>
                    <th class="text-center">联系地址</th>
                    <th class="text-center">操作</th>
                </tr>
                <volist name="info" id="vo">
                    <tr class="vendor_{$vo['vendor_id']}">
                        <td>{$vo['vendor_code']}</td>
                        <td>{$vo['vendor_name']}</td>
                        <td>{$vo['vendor_contacts']}</td>
                        <td>{$vo['contacts_phone']}</td>
                        <td>{$vo['vendor_address']}</td>
                        <td class="text-center">
                            <span onclick='showinfo({$vo['vendor_id']})'><span class='glyphicon glyphicon-zoom-in text-info' ></span> 查看详细信息</span> 
                            |
                            <span onclick='deleteinfo({$vo['vendor_id']})'><span class='glyphicon glyphicon-trash text-danger'></span> 删除</span>
                        </td>
                    </tr>
                </volist> 
            </table>
        </div>
            <div class="row text-center">
                <button class="btn btn-defalut" onclick="load_desc()"><<</button>
                <button class="btn btn-defalut" onclick="load_add()">>></button>
            </div>
      </div>
      <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
      </div>

    </div>
  </div>
</div>

<script type="text/javascript">
    var page=0;
    var line=1;
    var trn={$count};
    var item=0;
    load_add();
    item_add();
    function load_add(){
        page=page+1;
        $.ajax({
            // url:'/qwadmin/index.php/Qwadmin/Vendor/vendor_search/?name='+info,
            url:'{:U('Vendor/page')}?page='+page,
            success:function(data){
                table(data);
            }
        })
    }
    function load_desc(){
        page=page-1;
        if(page<=0){
            page=1;
        }
        $.ajax({
            // url:'/qwadmin/index.php/Qwadmin/Vendor/vendor_search/?name='+info,
            url:'{:U('Vendor/page')}?page='+page,
            success:function(data){
                table(data);
            }
        })
    }
    function item_add(){
        item=item+1;
        $.ajax({
            // url:'/qwadmin/index.php/Qwadmin/Vendor/vendor_search/?name='+info,
            url:'{:U('Itemno/page')}?page='+item,
            success:function(data){
                table_item(data);
            }
        })
    }
    function item_desc(){
        item=item-1;
        if(item<=0){
            item=1;
        }
        $.ajax({
            // url:'/qwadmin/index.php/Qwadmin/Vendor/vendor_search/?name='+info,
            url:'{:U('Itemno/page')}?page='+item,
            success:function(data){
                table_item(data);
            }
        })
    }
    $(".vendor-search").click(function(){
        var code=$(".vendor-input-code").val();
        var name=$(".vendor-input-name").val();
        $.ajax({
            // url:'/qwadmin/index.php/Qwadmin/Vendor/vendor_search/?name='+info,
            url:'{:U('Vendor/vendor_search')}?name='+name+'&code='+code,
            success:function(data){
                table(data);
            }
        })
    })
    function table(data){
        $(".vendor-table").html("");
        var trh=$("<tr></tr>");
        var th_0=$("<th class='text-center'>供应商编号</th>");
        var th_1=$("<th class='text-center'>供应商名称</th>");
        var th_2=$("<th class='text-center'>联系人</th>");
        var th_3=$("<th class='text-center'>联系电话</th>");
        var th_4=$("<th class='text-center'>联系地址</th>");
        var th_5=$("<th class='text-center'>操作</th>");
        th_0.appendTo(trh);
        th_1.appendTo(trh);
        th_2.appendTo(trh);
        th_3.appendTo(trh);
        th_4.appendTo(trh);
        th_5.appendTo(trh);
        trh.appendTo(".vendor-table");
        for(x in data){
            var tr=$("<tr class='vendor_"+data[x].vendor_id+"'></tr>");
            var td_0=$("<td>"+data[x].vendor_code+"</td>");
            var td_1=$("<td>"+data[x].vendor_name+"</td>");
            var td_2=$("<td>"+data[x].vendor_contacts+"</td>");
            var td_3=$("<td>"+data[x].contacts_phone+"</td>");
            var td_5=$("<td>"+data[x].vendor_address+"</td>");
            
            var td_4=$("<td class='text-center'><span onclick=add_one('"+data[x].vendor_code+"') class='text-success glyphicon glyphicon-plus'></span></td>");
            td_0.appendTo(tr);
            td_1.appendTo(tr);
            td_2.appendTo(tr);
            td_3.appendTo(tr);
            td_5.appendTo(tr);

            td_4.appendTo(tr);
            tr.appendTo(".vendor-table")
        }
    }
    function table_item(data){
        $(".item-table").html("");
        var trh=$("<tr></tr>");
        var th_0=$("<th class='text-center'>料号</th>");
        var th_1=$("<th class='text-center'>料号描述</th>");
        var th_2=$("<th class='text-center'>单位</th>");
        var th_3=$("<th class='text-center'>供应商编号</th>");
        var th_4=$("<th class='text-center'>售价</th>");
        var th_5=$("<th class='text-center'>操作</th>");
       
        th_0.appendTo(trh);
        th_1.appendTo(trh);
        th_2.appendTo(trh);
        th_3.appendTo(trh);
        th_4.appendTo(trh);
        th_5.appendTo(trh);
       
        trh.appendTo(".item-table");
        for(x in data){
            var tr=$("<tr></tr>");
            var td_0=$("<td>"+data[x].item_no+"</td>");
            var td_1=$("<td>"+data[x].item_desc+"</td>");
            var td_2=$("<td>"+data[x].units+"</td>");
            var td_3=$("<td>"+data[x].supplier_name+"</td>");
            var td_4=$("<td>"+data[x].unit_price+"</td>");
            var combine=data[x].item_no+"|"+data[x].units+"|"+data[x].unit_price;
            
            var td_5=$("<td class='text-center'><span onclick=add_item('"+combine+"') class='text-success glyphicon glyphicon-plus'></span></td>");
            td_0.appendTo(tr);
            td_1.appendTo(tr);
            td_2.appendTo(tr);
            td_3.appendTo(tr);
            td_4.appendTo(tr);

            td_5.appendTo(tr);
            tr.appendTo(".item-table")
        }
    }
    $(".item-search").click(function(){
        var no=$(".item-no").val();
        var de=$(".item-de").val();
        var ve=$(".item-ve").val();
        $.ajax({
            url:'{:U('Itemno/achieve')}?no='+no+'&ve='+ve+'&de'+de,
            success:function(data){
                table_item(data);
            }
        })
    })
    $("input[name=vendor_code]").click(function(){
        $(".ck-lg").modal('show');
    })
     function add_one(data){
        if (data) {
            $("input[name=vendor_code]").val(data);
            $(".ck-lg").modal('hide');
        }
    }
    // $(".coc").click(function(){
    //     $(".line_h").removeClass('hide');
    //     $(this).addClass('hide');
   
    // })
    function show_item(id){
        line=id;
        $(".ck-item").modal('show');
    }
    function add_item(data){
        var m=new Array();
        m=data.split("|");
        $(".stockid"+line).val(m[0]);
        $(".uom"+line).val(m[1]);
        $(".price"+line).val(m[2]);
         $(".ck-item").modal('hide');
    }
    function addrtr(){
        //line_table                                                   
        var tr=$("<tr></tr>");
        var td_1=$("<td><input type='text' name='number[]' placeholder='行号' value='"+trn+"'></td>");
        var td_2=$("<td><input type='text' name='stockid[]' placeholder='料号' class='stockid"+trn+"' onclick='show_item("+trn+")'></td>");
        var td_3=$("<td><input type='text' name='uom[]' placeholder='单位' onclick='show_item("+trn+")' class='uom"+trn+"'></td>");
        var td_4=$("<td><input type='number' name='quantity[]' placeholder='数量' ></td>");
        var td_5=$("<td><input type='text' name='price[]' placeholder='单价' onclick='show_item("+trn+")' class='price"+trn+"'></td>");
        var td_6=$("<td><input type=\"text\" name=\"notee[]\" placeholder=\"记录\"></td>");
        td_1.appendTo(tr);
        td_2.appendTo(tr);
        td_3.appendTo(tr);
        td_4.appendTo(tr);
        td_5.appendTo(tr);
        td_6.appendTo(tr);
        tr.appendTo(".line_table");
        trn=trn+1;
    }
    function dellh(lh){
        var id=confirm("确认是否删除");
        if(id){
             $.ajax({
                url:'{:U('Headersall/delline')}?po_num={$_GET['id']}&line='+lh,
                success:function(data){
                    if(data.status){
                        $(".lh"+lh).remove();
                    }
                }
             })
        }
    }
</script>

    </body>
</html>